﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Model;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Infrastructure.Common;

namespace Xiaov.SmartWeb.Application.SysAdmin
{
    public partial class Admin_Password : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tb_userName.Text = this.PUser.USERNAME;
            }
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            string old=tb_password.Text.Encrypt();
            string n= tb_newpassword.Text.Encrypt();
            string r= tb_repeatpassword.Text.Encrypt();
            PUser.USERNAME = tb_userName.Text.ToString();
            if (tb_password.Text != "")
            {
                //如果旧密码有值 说明要修改密码
                if (r != n)
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("输入的新密码两次不一致！", "Admin_Password.aspx");
                if (old != PUser.PASSWORD)
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("旧密码输入不正确！", "Admin_Password.aspx");
                if (tb_newpassword.Text == "")
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("新密码不能为空！", "Admin_Password.aspx");
                PUser.PASSWORD = r;                
            }
            else
            {
                if(tb_newpassword.Text!="")
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("旧密码必须输入！", "Admin_Password.aspx");
            }
            PUser.Save();
           Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("保存成功！", "Admin_Password.aspx");
        }
    }
}